package plugins;

import java.util.HashSet;
import java.util.Set;

import org.bukkit.command.CommandExecutor;
import org.bukkit.plugin.java.JavaPlugin;

import persistence.CSubPlugin;
import persistence.ICommandHandler;
import persistence.IConfigurable;
import persistence.IStorage;
import commands.CCommandHandler;
import commands.ICommand;

public class BAKACommand extends CSubPlugin implements ICommandHandler {
	private CCommandHandler handler;
	
	public BAKACommand(JavaPlugin parent) {
		super(parent);
	}

	public final String SUB_PLUGIN_NAME =  BAKACommand.class.getName();

	@Override
	public String getName() {
		return SUB_PLUGIN_NAME;
	}

	@Override
	public boolean onEnable() {
		handler = new CCommandHandler(this);
		for(ICommand cmd : handler.getAllCmd().values())
		{
			if(cmd instanceof IStorage) ((IStorage)cmd).LoadData();
			else if(cmd instanceof IConfigurable) ((IConfigurable)cmd).getConfig().saveConfig();
		}
		return true;
	}

	@Override
	public boolean onDisable() {
		for(ICommand cmd : handler.getAllCmd().values())
		{
			if(cmd instanceof IStorage) ((IStorage)cmd).SaveData();
			else if(cmd instanceof IConfigurable) ((IConfigurable)cmd).getConfig().saveConfig();
		}
		return true;
	}

	@Override
	public Set<String> getCommandBindStrings() {
		return new HashSet<String>(handler.getAllCmd().keySet());
	}

	@Override
	public CommandExecutor getExecutor() {
		return handler;
	}


}
